package br.com.sig.security.business.model.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import br.com.sig.business.model.entity.BaseEntity;

@Entity
@Table(schema="sig_security", name="`user`")
public class User extends BaseEntity {

	private static final long serialVersionUID = -5017824520579753974L;
		
	private String userName;
	private String password;
	private Boolean active;
	private List<Role> roles;
//	private Funcionario funcionario;

	public User() {
	}
	
	public User(String userName) {
		this.userName = userName;
	}	
	
	@Column(nullable=false, unique = true)
	@NotNull
	public String getUserName() {
		return userName;
	}
	
	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	@Column(nullable=false)
	@NotNull
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	@Column(nullable=false)
	@NotNull
	public Boolean getActive() {
		return active;
	}
	
	public void setActive(Boolean active) {
		this.active = active;
	}
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(
		schema="sig_security",
		name = "user_has_role",
		joinColumns = @JoinColumn(name = "id_user", nullable = false),
		inverseJoinColumns = @JoinColumn(name = "id_role", nullable = false)
	)
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

}